package org.pro.core.validateCode;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.pro.core.constant.SecurityConstants;
import org.pro.core.validateCode.processor.ValidateCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 验证码控制器
 * @author luoqiz
 *
 */
@RestController
public class ValidateCodeController {
	
	/**
	 * 收集系统中{@link ValidateCodeGenerator}接口的实现
	 */
	@Autowired
	private Map<String, ValidateCodeProcessor> validateCodeProcessors;

	/**
	 * 创建验证码，根据验证码类型不同，调用不同的{@link ValidateCodeGenerator}接口的实现
	 * @param request
	 * @param response
	 * @param type
	 * @throws Exception 
	 */
	@GetMapping(SecurityConstants.SYSTEM_GET_AUTH_VALIDATE+"/{type}") //image sms
	public void imageGenarator(HttpServletRequest request,HttpServletResponse response, @PathVariable String type) throws Exception {
		validateCodeProcessors.get(type+ValidateCodeProcessor.class.getSimpleName()).createValidateCode(new ServletWebRequest(request,response));
	}
}
